import type { FileObject } from './public'

export enum OrderStatus {
  /** 待付款 */
  daifukuan = 1,
  /** 待审核 */
  daishenhe = 2,
  /** 待发货 */
  daifahuo = 3,
  /** 待收货 */
  daishouhuo = 4,
  /** 待归还 */
  daiguihuan = 5,
  /** 归还中 */
  guihuanzhong = 6,
  /** 已完成 */
  jiaoyiwancheng = 7,
  /** 完结订单 */
  wanjie = 8,
  /** 已关闭(用户) */
  yonghuguanbi = 9,
  /** 已关闭(系统) */
  xitongguanbi = 10,
  /** 已关闭(商家) */
  shangjiaguanbi = 11,
  /** 已完成 */
  yiwancheng = 12,
  /** 即将到期 */
  jijiangdaoqi = 13,
  /** 申请取消 */
  shenqingquxiao = 14,
  /** 退款中 */
  tuikuanzhong = 15,
}

// 思路：列表和详情共用 OrderItem，其中的 OrderItem... 特殊定义是 item 中部分字段给的
// 是 json 字符串，需要在页面中处理格式化，此处提供类型供页面按需定义时使用

export interface OrderItem {
  id: number
  status: number
  leaseTerm: number
  replenish: number
  human: number
  jzqSignFile: Record<string, any>
  jzqSignReceivePhoneFile: Record<string, any>
  jzqSignReceivePromiseFile: Record<string, any>
  signFlowFinish: number
  shopsUserOutGoods: Record<string, any>
  province: string
  city: string
  district: string
  address: string
  tit: string
  phone: string
  ordercode: string
  num: string
  createtime: number
  productOrderExtra: any[]
  subStatus: number
  flowOne: any // 可能不存在
  riskRejectReason: string
  paymentParams: {
    total_freeze_amount: string
  }
  productOrderRecordVoList: {
    id: number
    price: number
    period: number
    expiretime: number
    duetime: number
    payment: number
    paymentRecordList: Record<string, any>[]
  }[]
  productOrderShipment: {
    cont: {
      data: {
        status: string
        time: string
        context: string
      }[]
    }
  }
  haveOverdueFine: string | number
  shopsVo: {
    selectOrgId: null
    id: number
    parentId: number
    orgId: number
    path: string
    realPath: string
    tit: string
    phone: string
    firmName: string
    authenticationName: string
    address: string
    pushCity: string
    subjectSubType: number
    note: string
    zfb: string
    zfbName: string
    firmZfb: string
    name: string
    rent: number
    bxMoney: number
    balance: number
    profitSharingAmount: number
    level: number
    identNumber: string
    mobile: string
    ratio: number
    createTime: number
    license: string
    image: string
    corpCode: string
    outdoorImage: string
    provinceCode: string
    cityCode: string
    districtCode: string
    contractUserInfo: string
    contractApplyInfo: null
    signSealId: string
    longitude: string
    latitude: string
    contractFile: null
    riskAutoTransfer: number
    otherParam: {
      sendSMS: number
      openLiuLiangFei: number
      shipping: number
      liuLianRate: number
      caseAllocation: number
      autoGenerateBill: string
      doubleAgreement: number
      autoKouArr: {
        price: string
        dictId: number
        type: string
        isUse?: boolean
      }[]
      autoFenBillMaxValue: number
      autoFenBill: number
    }
    authoritylist: null
    sort: number
    orderExtraBalancePrice: null
    parentTit: null
    cloudService: null
    ids: null
    openSell: null
  }
  params: {
    id: number
    model: {
      price: number
      leaseTerm: string
    }
    title: string
    image: string
    detail: string
    deposit: number
    worryMoney: number
    orderPriceList: {
      date: string
      price: string
    }[]
  }
  contractSignflow?: null | {
    flowId: string
    accountId: string
    signNo: string
    status: string
    docList: {
      accountId: string
      downloadUrl: string
      fileId: string
      fileItemNo: string
      fileName: string
      fileSize: number
      merchantUploadUrl: string
    }[]
    orderId: string
    reqMsgId: string
    shortUrl: string
    resultMsg: string
    antOrderId?: string
    resultCode: string
    alipayUserId: string
    businessScene: string
  }
  /** 收货方式 */
  shippingMode: number // 0 自提  1 邮寄
  extraInfo: {
    /** 全新/二手 */
    type: string
  }
  mode: number
  agreement: number
}

export interface OrderListReq {
  pageNo?: number
  pageSize?: number
  status?: number
  id?: number
}
export interface OrderListRes {
  total: number
  pageSize: number
  pages: number
  selectOrgId: null | string
  pageNo: number
  totalPage: number
  totalCount: number
  data: OrderItem[]
}

export interface SubBillItem {
  id: number
  payMoney: number
  status: number
  planTime: string
  realPayTime: string
}
export interface SubBillRes {
  [x: number]: SubBillItem[]
}

export interface OrderServerReq {
  oid: number
  page: false
}
export interface OrderServerItem {
  body: null
  createdTime: string
  extraPrice: number
  filterByShopId: null
  hidden: number
  id: number
  name: string
  oid: number
  orderCode: string
  orderTitle: string
  orgId: number
  orgName: null
  outOrderNo: null
  payType: number
  ratio: null
  realPrice: null
  remark: null
  selectOrgId: null
  shopsName: null
  sid: number
  status: number
  tit: string
  tradeNo: null
  type: number
  updatedBy: null
  updatedTime: string
}

export interface CancelOrRefundOrderReq {
  cont: string
}

export interface GeneratePayFineRes {
  body: any | null
  createdTime: string
  day: any | null
  expiretime: any | null
  id: number
  ids: any | null
  name: any | null
  oid: number
  orderCode: string
  orgId: any | null
  overdueDay: any | null
  overdueFine: number
  paymentStatus: any | null
  period: any | null
  phone: any | null
  price: any | null
  ratio: any | null
  rid: any | null
  selectOrgId: any | null
  tradeNo: any | null
  type: number
  updatedBy: any | null
  updatedTime: any | null
}

export interface OverdueListReq {
  oid: number
  pageNo?: number
  pageSize?: number
}

export interface OverdueListRes {
  data: {
    createdTime: string
    ratio: number
    type: number
    overdueFine: number
  }[]
  totalPage: number
  totalCount: number
}

export interface GetAddressByJwdReq {
  location: string
}
interface Location {
  lng: number
  lat: number
}
export interface GetAddressByJwdRes {
  message: string
  request_id: string
  status: number
  result: {
    address: string
    ad_info: {
      _distance: number
      province: string
      adcode: string
      nation: string
      city: string
      district: string
      name: string
      city_code: string
      location: Location
      nation_code: string
      phone_area_code: string
    }
    address_reference: Record<string, any>
    location: Location
    formatted_addresses: Record<string, any>
    address_component: Record<string, any>
  }
}

export interface NewTradePay {
  totalAmount: number
  subject: string
  objId: number
  type: 0 | 1 | 2 // 0 服务保障  1 分期支付  2 违约金
  buyerId?: string
}

export interface JZQGetSignLink {
  oid: number
  useCustomDomain: number
}

export interface UpdateRiskControlAttachmentRequest {
  /** 工作证明 */
  workCertificate: FileObject[]
  /** 收入证明 */
  incomeCertificate: FileObject[]
  /** 芝麻信用 */
  zhimaCreditRecording: FileObject[]
  /** 资产证明 */
  assetCertificate: FileObject[]
  /** 其他材料 */
  otherDocuments: FileObject[]
  /** 联系人 */
  contactPerson: {
    /** 联系人1名称 */
    userNameOne: string
    /** 联系人1手机号 */
    userPhoneOne: string
    /** 联系人1图片 */
    userUrlOne?: FileObject[]
    /** 联系人1关系 */
    emergencyContactOne: string
    /** 联系人2名称 */
    userNameTwo: string
    /** 联系人2手机号 */
    userPhoneTwo: string
    /** 联系人2图片 */
    userUrlTwo?: FileObject[]
    /** 联系人2关系 */
    emergencyContactTwo: string
  }
}

export interface RiskControlAttachmentResponse {
  /** 工作证明 */
  workCertificate: FileObject[]
  /** 收入证明 */
  incomeCertificate: FileObject[]
  /** 芝麻信用 */
  zhimaCreditRecording: FileObject[]
  /** 资产证明 */
  assetCertificate: FileObject[]
  /** 其他材料 */
  otherDocuments: FileObject[]
  /** 联系人 */
  contactPerson: {
    /** 联系人1名称 */
    userNameOne: string
    /** 联系人1手机号 */
    userPhoneOne: string
    /** 联系人1图片 */
    userUrlOne?: FileObject[]
    /** 联系人1关系 */
    emergencyContactOne: string
    /** 联系人2名称 */
    userNameTwo: string
    /** 联系人2手机号 */
    userPhoneTwo: string
    /** 联系人2图片 */
    userUrlTwo?: FileObject[]
    /** 联系人2关系 */
    emergencyContactTwo: string
  } | null
}

export interface UpdateRiskControlAttachmentRequest {
  /** 工作证明 */
  workCertificate: FileObject[]
  /** 收入证明 */
  incomeCertificate: FileObject[]
  /** 芝麻信用 */
  zhimaCreditRecording: FileObject[]
  /** 资产证明 */
  assetCertificate: FileObject[]
  /** 其他材料 */
  otherDocuments: FileObject[]
  /** 联系人 */
  contactPerson: {
    /** 联系人1名称 */
    userNameOne: string
    /** 联系人1手机号 */
    userPhoneOne: string
    /** 联系人1图片 */
    userUrlOne?: FileObject[]
    /** 联系人1关系 */
    emergencyContactOne: string
    /** 联系人2名称 */
    userNameTwo: string
    /** 联系人2手机号 */
    userPhoneTwo: string
    /** 联系人2图片 */
    userUrlTwo?: FileObject[]
    /** 联系人2关系 */
    emergencyContactTwo: string
  }
}

export interface ReceivingAttachmentRequest {
  oid: number
}

export interface ReceivingAttachmentResponse {
  /** 0 手机 1 电动车 */
  // mode: 0 | 1

  /** 当前合同 */
  currentContract: FileObject[]
  /** 回执单   */
  // receivingReceipt: FileObject[]
  /** 订单确认 */
  orderConfirmed: FileObject[]
  /** 新机拆封 */
  newMachineOpened: FileObject[]
  /** 新机加锁 */
  newMachineLocked: FileObject[]
  /** 其他 */
  other: FileObject[]
  /** 手持身份证和电动车合格证 */
  identityAndVehicleCertificatePhotos?: FileObject[]
  /** 锁车完成后锁车系统 */
  lockSystemCompletion?: FileObject[]
}

export interface UpdateReceivingAttachmentInfoRequest {
  /** 订单ID */
  oid: number
  /** 当前合同 */
  currentContract?: FileObject[]
  /** 回执单 */
  receivingReceipt?: FileObject[]
  /** 订单确认 */
  orderConfirmed?: FileObject[]
  /** 新机拆封 */
  newMachineOpened?: FileObject[]
  /** 其他 */
  other?: FileObject[]
  /** 手持身份证和电动车合格证 */
  identityAndVehicleCertificatePhotos?: FileObject[]
  /** 锁车完成后锁车系统 */
  lockSystemCompletion?: FileObject[]
}
